package com.khstudio.filebrowser.duallist;

import java.io.File;

import com.khstudio.filebrowser.util.KhFile;

public class KhFileBrowserItem {
    public enum TYPE {
        UP,
        SDCARD,
        EXTSDCARD,
        FOLDER,
        UNKNOWN,
        IMAGE,
        VIDEO
    }

    private String      path;
    private TYPE        type;
    private boolean     select;

    public KhFileBrowserItem(String path, TYPE type) {
        this.path       = path;
        this.type   = type;
        this.select     = false;
    }

    public void setType(TYPE type)      { this.type = type; }
    public void setSelect(boolean b)    { this.select = b;}

    public String       getPath()       { return path; }
    public TYPE         getType()       { return type;}
    public boolean      getSelect()     { return select;}
    public String       getName() {
        if(type == TYPE.UP) {
            return "..";
        } else if(type == TYPE.SDCARD) {
            return "SD Card";
        } else if(type == TYPE.EXTSDCARD) {
            return "External SD Card";
        }

        int separatorIndex = path.lastIndexOf(File.separator);
        return (separatorIndex < 0) ? path : path.substring(separatorIndex + 1, path.length());
    }

    public static TYPE getType(String url) {
        String mime = KhFile.getMimeType(url);

        if(mime == null) {
            return TYPE.UNKNOWN;
        }

        int separatorIndex = mime.lastIndexOf('/');
        String top = separatorIndex < 0 ? mime : mime.substring(0, separatorIndex);

        if(top.equals("image")) {
            return TYPE.IMAGE;
        } else if(top.equals("video")) {
            return TYPE.VIDEO;
        } else {
            return TYPE.UNKNOWN;
        }
    }
}